package com.mck.controller;

import com.mck.entity.Classname;
import com.mck.entity.Result;
import com.mck.service.ClassnameService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0.0
 * @Author mck
 * @Date 2025/1/27 下午5:24
 * @注释 班级管理
 */

@RestController
@RequestMapping("/api/public/classname")
@Slf4j
public class ClassnameController {

    @Autowired
    private ClassnameService classnameService;

    // 获取班级列表
    @GetMapping
    public Result getClassList(){
        log.info("获取班级列表");

        List<Classname> classList = classnameService.getClassnameList();
        // System.out.println(classList);
        return Result.success(classList);
    }

    // 通过id获取班级
    @GetMapping("/{classnameId}")
    public Result getClassnameById(@PathVariable Integer classnameId){
        log.info("通过id获取班级");

        Classname classname = classnameService.getClassnameById(classnameId);
        return Result.success(classname);
    }

    // 添加班级
    @PostMapping
    public Result addClassname(@RequestBody Classname classname){
        System.out.println(classname);
        log.info("添加班级");

        classnameService.addClassname(classname);
        return Result.success();
    }

    // 添加班级列表
    @PostMapping("/list")
    public Result addClassnameList(@RequestBody List<Classname> classnameList){
        log.info("添加班级列表");

        classnameService.addClassnameList(classnameList);
        return Result.success();
    }

    // 更新班级
    @PutMapping
    public Result updateClassname(@RequestBody Classname classname){
        log.info("更新班级");

        classnameService.updateClassname(classname);
        return Result.success();
    }

    // 删除班级
    @DeleteMapping("/{classnameId}")
    public Result deleteClassname(@PathVariable Integer classnameId){
        log.info("删除班级");

        classnameService.deleteClassname(classnameId);
        return Result.success();
    }
}
